home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
mac
/
files
/
infodata
/
callbook.tar
/
callbook_1.3
/
print.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-31
|
6KB
|
373 lines
/*
* Telnet callsign server sources copyright 1989 by Devon Bowen, KA2NRC.
* You may distribute and modify these files as you please as long as
* as long as credit to the original creator is given. Please report any
* bug fixes or modification to bowen@cs.buffalo.edu.
*/
#include <stdio.h>
#include <ctype.h>
#include "callbook.h"
char *index(), *cvtdate();
int p_data(), p_name(), p_raw(), p_addr();
int (*p_routine[])() = { p_data, p_name, p_raw, p_addr };
p_name(buffer, not_first)
char *buffer;
int not_first;
{
int count;
char *fields[19];
char temp[BUFSIZ];
fields[0] = buffer;
for (count=1; count<19; count++) {
fields[count] = index(fields[count-1], '|');
*(fields[count]++) = '\0';
}
sprintf(temp, "%-13s%s ", fields[0], fields[3]);
if (*fields[4]) {
strcat(temp, fields[4]);
strcat(temp, " ");
}
if (*fields[1]) {
strcat(temp, fields[1]);
strcat(temp, " ");
}
if (*fields[2])
strcat(temp, fields[2]);
strcat(temp, "\n");
if (tputs(temp, 0))
return 1;
return 0;
}
p_raw(buffer, not_first)
char *buffer;
int not_first;
{
if (tputs(buffer, 0))
return 1;
if (tputs("\n", 0))
return 1;
return 0;
}
p_data(buffer, not_first)
char *buffer;
int not_first;
{
int count, was_call=0;
char *fields[19];
char temp1[BUFSIZ];
char temp2[BUFSIZ];
fields[0] = buffer;
while (isspace(*fields[0]))
fields[0]++;
for (count=1; count<19; count++) {
fields[count] = index(fields[count-1], '|');
*(fields[count]++) = '\0';
while (*fields[count] == ' ')
fields[count]++;
}
if (not_first)
if (tputs("\n", 0))
return 1;
sprintf(temp2, "Call-Sign: %-25s", fields[0]);
switch (*fields[15]) {
case 'N' : strcat(temp2, "Class: NOVICE\n");
was_call=1;
break;
case 'T' : strcat(temp2, "Class: TECHNICIAN\n");
was_call=1;
break;
case 'G' : strcat(temp2, "Class: GENERAL\n");
was_call=1;
break;
case 'A' : strcat(temp2, "Class: ADVANCED\n");
was_call=1;
break;
case 'E' : strcat(temp2, "Class: EXTRA\n");
was_call=1;
break;
default : strcat(temp2, "\n");
break;
}
if (tputs(temp2, 0))
return 1;
if (*fields[16] || *fields[17]) {
sprintf(temp2, "Previously: %-24s",
(*fields[16] ? fields[16] : "SAME CALL"));
if (*fields[17])
switch (*fields[17]) {
case 'N' :
strcat(temp2, "Class: NOVICE\n");
break;
case 'T' :
strcat(temp2, "Class: TECHNICIAN\n");
break;
case 'G' :
strcat(temp2, "Class: GENERAL\n");
break;
case 'A' :
strcat(temp2, "Class: ADVANCED\n");
break;
case 'E' :
strcat(temp2, "Class: EXTRA\n");
break;
}
else
if (was_call)
strcat(temp2, "Class: SAME CLASS\n");
else
strcat(temp2, "\n");
if (tputs(temp2, 0))
return 1;
}
strcpy(temp1, fields[3]);
if (*fields[4]) {
strcat(temp1, " ");
strcat(temp1, fields[4]);
}
if (*fields[1]) {
strcat(temp1, " ");
strcat(temp1, fields[1]);
}
if (*fields[2]) {
strcat(temp1, " ");
strcat(temp1, fields[2]);
}
sprintf(temp2, "Real Name: %-25s", temp1);
if (*fields[5]) {
sprintf(temp1, "Birthday: %s\n", cvtdate(fields[5],1));
strcat(temp2, temp1);
} else
strcat(temp2, "\n");
if (tputs(temp2, 0))
return 1;
if (*fields[8] || *fields[9] || *fields[10] || *fields[11]) {
strcpy(temp2, "Mailing Address: ");
if (*fields[8]) {
strcat(temp2, fields[8]);
strcat(temp2, ", ");
}
if (*fields[9]) {
strcat(temp2, fields[9]);
strcat(temp2, ", ");
}
if (*fields[10]) {
strcat(temp2, fields[10]);
strcat(temp2, " ");
}
if (*fields[11]) {
strcat(temp2, fields[11]);
}
strcat(temp2, "\n");
if (tputs(temp2, 0))
return 1;
}
if (*fields[12] || *fields[13] || *fields[14]) {
strcpy(temp2, "Station Address: ");
if (*fields[12] == '*') {
strcat(temp2, "SAME AS MAILING ADDRESS\n");
} else {
if (*fields[12]) {
strcat(temp2, fields[12]);
strcat(temp2, ", ");
}
if (*fields[13]) {
strcat(temp2, (*fields[13]=='*' ? fields[9] :
fields[13]));
strcat(temp2, ", ");
}
if (*fields[14])
strcat(temp2, (*fields[14]=='*' ? fields[10] :
fields[14]));
strcat(temp2, "\n");
}
if (tputs(temp2, 0))
return 1;
}
if (*fields[6]) {
sprintf(temp2, "Valid From: %-24s", cvtdate(fields[6],1));
if (*fields[7]) {
strcat(temp2, "To: ");
strcat(temp2, cvtdate(fields[7],0));
}
strcat(temp2, "\n");
if (tputs(temp2, 0))
return 1;
}
if (*fields[18] && (*fields[18] != '*' || *fields[6])) {
sprintf(temp2, "Records Last Processed: %s\n",
(*fields[18] == '*' ? cvtdate(fields[6],1) :
cvtdate(fields[18],1)));
if (tputs(temp2, 0))
return 1;
}
return 0;
}
p_addr(buffer, not_first)
char *buffer;
int not_first;
{
int count;
char *fields[19];
char temp[BUFSIZ];
fields[0] = buffer;
for (count=1; count<19; count++) {
fields[count] = index(fields[count-1], '|');
*(fields[count]++) = '\0';
}
if (!not_first)
if (tputs("\n", 0))
return 1;
strcpy(temp, fields[3]);
if (*fields[4]) {
strcat(temp, " ");
strcat(temp, fields[4]);
}
if (*fields[1]) {
strcat(temp, " ");
strcat(temp, fields[1]);
}
if (*fields[2]) {
strcat(temp, " ");
strcat(temp, fields[2]);
}
strcat(temp, " (");
strcat(temp, fields[0]);
strcat(temp, ")\n");
if (tputs(temp, 0))
return 1;
if (tputs(fields[8], 0))
return 1;
if (tputs("\n", 0))
return 1;
sprintf(temp, "%s, %s %s\n\n", fields[9], fields[10], fields[11]);
if (tputs(temp, 0))
return 1;
return 0;
}
#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
#define CENTURY 20
char *
cvtdate(s,before)
char *s;
int before;
{
static char buf[BUFSIZ];
register char *cp;
int day, year;
static struct month {
char *name;
int days;
} *mp, mtab[] = {
"JAN",31,"FEB",28,"MAR",31,"APR",30,"MAY",31,"JUN",30,
"JUL",31,"AUG",31,"SEP",30,"OCT",31,"NOV",30,"DEC",31
};
strcpy(buf, s);
cp = buf;
cp += 2;
day = atoi(cp);
*cp = '\0';
year = (CENTURY - 1) * 100 + atoi(buf);
if (year > DB_YEAR && before) year -= 100;
if (year < DB_YEAR && !before) year += 100;
mtab[1].days = isleap(year) ? 29 : 28;
for (mp = mtab; day > mp->days; mp++)
day -= mp->days;
sprintf(buf, "%s %d, %d", mp->name, day, year);
return(buf);
}